/**
 * 
 */
package com.gkwave.action.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gkwave.module.bean.RouteBean;
import com.gkwave.module.dao.TransportSearchDAO;

/**
 * @author Administrator
 *
 */
public class TransportSearchService extends BaseService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 823347604199044903L;

	/* (non-Javadoc)
	 * @see com.gkwave.action.service.BaseService#procesRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public void procesRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		out = response.getWriter();
    	String typeofSearch = request.getParameter("typeofSearch");
    	String idCity = request.getParameter("idCity");
    	String idBoardingLocationId = request.getParameter("idBoardingLocationId");
    	String idEndLocationId = request.getParameter("idEndLocationId");
    	String idRoute = request.getParameter("idRoute");
    	String tsTime = request.getParameter("tsTime");
		/*
		 * typeofSearch
		 * 1-Morning search
		 * 2-Evening search
		 * 3-LMS and MMTS
		 * 4-Route Number based search
		 * 5-Time based search
		*/
    	Integer typeOfSearch = 0;
    	Integer id_city = 99999;
    	Integer id_boarding_locationId = 99999;
    	Integer id_end_locationId = 99999;
    	TransportSearchDAO dao = null;
    	Integer id_route = 99999;
    	RouteBean bean = null;
    	
    	if(typeofSearch!=null){
	    	try {
	    		typeOfSearch = Integer.parseInt(typeofSearch);
//	    		id_city = Integer.parseInt(idCity);
//	    		id_boarding_locationId = Integer.parseInt(idBoardingLocationId);
//	    		id_end_locationId = Integer.parseInt(idEndLocationId);
	    		
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
			System.out.println("typeOfSearch : " + typeOfSearch);
			
	    	switch (typeOfSearch) {
			case 1:
				if(idBoardingLocationId!=null && idEndLocationId!=null){
		    		id_boarding_locationId = Integer.parseInt(idBoardingLocationId);
		    		id_end_locationId = Integer.parseInt(idEndLocationId);
					dao = new TransportSearchDAO();
					bean = dao.getTransportSearchList(id_boarding_locationId,id_end_locationId);
				}
				break;
			case 2:
				if(idBoardingLocationId!=null && idEndLocationId!=null){
					id_boarding_locationId = Integer.parseInt(idBoardingLocationId);
		    		id_end_locationId = Integer.parseInt(idEndLocationId);
					dao = new TransportSearchDAO();
					bean = dao.getTransportSearchList(id_boarding_locationId,id_end_locationId);
				}
				break;
			case 3:
				if(idBoardingLocationId!=null && idEndLocationId!=null){
		    		id_boarding_locationId = Integer.parseInt(idBoardingLocationId);
		    		id_end_locationId = Integer.parseInt(idEndLocationId);
					dao = new TransportSearchDAO();
					bean = dao.getTransportLMSSearchList(id_boarding_locationId,id_end_locationId);
				}
				break;
			case 4:
				if(idRoute!=null){
					dao = new TransportSearchDAO();
					id_route = Integer.parseInt(idRoute);
					bean = dao.getTransportSearchList(id_route);
				}
				break;
			case 5:
				if(idBoardingLocationId!=null && tsTime!=null){
				dao = new TransportSearchDAO();
				Integer id_location = Integer.parseInt(idBoardingLocationId);
				bean = dao.getTransportSearchList(id_location,tsTime);
				}
				break;			
			default:
				
				break;
			}
    	}
		if (bean != null) {
			xmlResponse = bean.marsel(bean);
		} else{
			xmlResponse = "Null input!!!";
		}
		System.out.println(xmlResponse);
		out.println(xmlResponse);
	}

}
